package Memento;

/**
 * @author Cjj
 * 使用CareTaker和Originator类来演示备忘录模式
 */
public class MementoPatternDemo {
    public static void main(String[] args) {
       Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        originator.setState("State #1");
        originator.setState("State #2");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("State #3");
        careTaker.add(originator.saveStateToMemento());
        originator.setState("State #4");

        System.out.print("Current State:"+originator.getState());
        originator.getStateFromMemento(careTaker.get(0));
        System.out.print("First saved State："+originator.getState());
        originator.getStateFromMemento(careTaker.get(1));
        System.out.print("Second saved State："+originator.getState());
    }
}
